package com.wangtao.firstapp.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.wangtao.firstapp.R;

/**
 * 意见反馈页面
 * Created by lanouhn on 16/9/21.
 */
public class FeedBackActivity extends AppCompatActivity {
    private ImageView iv_back_titlebar_feedback;// 标题栏返回按钮
    private TextView tv_send_feedback;// 标题栏发送按钮
    private EditText et_content_feedback;// 意见正文
    private EditText et_number_feedback;// 联系方式

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_feedback);
        initView();
        initData();
        initEvent();
    }

    private void initView() {
        iv_back_titlebar_feedback = (ImageView) findViewById(R.id.iv_back_titlebar_feedback);// 标题栏返回按钮
        tv_send_feedback = (TextView) findViewById(R.id.tv_send_feedback);// 标题栏发送按钮
        et_content_feedback = (EditText) findViewById(R.id.et_content_feedback);// 意见正文
        et_number_feedback = (EditText) findViewById(R.id.et_number_feedback);// 联系方式
    }

    private void initData() {
        TextChange textChange = new TextChange();
        et_content_feedback.addTextChangedListener(textChange);
        et_number_feedback.addTextChangedListener(textChange);
    }

    private void initEvent() {
        // 标题栏返回按钮
        iv_back_titlebar_feedback.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        // 标题栏发送按钮
        tv_send_feedback.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(FeedBackActivity.this, "发送成功", Toast.LENGTH_SHORT).show();
                finish();
            }
        });
    }

    public class TextChange implements TextWatcher {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (et_content_feedback.length() > 0 && et_number_feedback.length() > 0) {
                tv_send_feedback.setTextColor(getResources().getColor(R.color.mycolor1));
                tv_send_feedback.setClickable(true);
            } else if (et_content_feedback.length() == 0 || et_number_feedback.length() == 0) {
                tv_send_feedback.setTextColor(getResources().getColor(R.color.mycolor3));
                tv_send_feedback.setClickable(false);
            }

        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    }


}
